﻿using System;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;

// Token: 0x020003BD RID: 957
public class SwitchUI : MonoBehaviour
{
	// Token: 0x17000255 RID: 597
	// (get) Token: 0x060017D4 RID: 6100 RVA: 0x0009CC68 File Offset: 0x0009AE68
	// (set) Token: 0x060017D5 RID: 6101 RVA: 0x0009CC70 File Offset: 0x0009AE70
	public bool Value
	{
		get
		{
			return this.value;
		}
		set
		{
			this.SetValue(value);
		}
	}

	// Token: 0x17000256 RID: 598
	// (get) Token: 0x060017D6 RID: 6102 RVA: 0x0009CC7C File Offset: 0x0009AE7C
	// (set) Token: 0x060017D7 RID: 6103 RVA: 0x0009CC84 File Offset: 0x0009AE84
	public bool Intaractable
	{
		get
		{
			return this.intaractable;
		}
		set
		{
			this.intaractable = value;
			this.on.interactable = value;
			this.off.interactable = value;
			if (this.noIntaractImage != null)
			{
				this.noIntaractImage.enabled = !value;
			}
		}
	}

	// Token: 0x060017D8 RID: 6104 RVA: 0x0009CCD0 File Offset: 0x0009AED0
	private void Start()
	{
		this.invoke = true;
		this.on.onValueChanged.AddListener(new UnityAction<bool>(this.OnChange_ON));
		this.off.onValueChanged.AddListener(new UnityAction<bool>(this.OnChange_OFF));
	}

	// Token: 0x060017D9 RID: 6105 RVA: 0x0009CD1C File Offset: 0x0009AF1C
	private void Update()
	{
		bool isOn = this.on.isOn;
		if (this.value != isOn)
		{
			this.value = isOn;
		}
	}

	// Token: 0x060017DA RID: 6106 RVA: 0x0009CD48 File Offset: 0x0009AF48
	public void SetValue(bool flag)
	{
		this.invoke = false;
		this.value = flag;
		if (flag)
		{
			this.on.isOn = true;
			this.off.isOn = false;
		}
		else
		{
			this.off.isOn = true;
			this.on.isOn = false;
		}
		this.invoke = true;
	}

	// Token: 0x060017DB RID: 6107 RVA: 0x0009CDA8 File Offset: 0x0009AFA8
	public void SetTitle(string str)
	{
		this.title.text = str;
	}

	// Token: 0x060017DC RID: 6108 RVA: 0x0009CDB8 File Offset: 0x0009AFB8
	public void Setup(string title, bool flag, UnityAction<bool> act)
	{
		this.title.text = title;
		this.SetValue(flag);
		this.onChange.AddListener(act);
	}

	// Token: 0x060017DD RID: 6109 RVA: 0x0009CDDC File Offset: 0x0009AFDC
	private void OnChange_ON(bool flag)
	{
		if (flag && this.onChange != null)
		{
			this.onChange.Invoke(true);
		}
	}

	// Token: 0x060017DE RID: 6110 RVA: 0x0009CDFC File Offset: 0x0009AFFC
	private void OnChange_OFF(bool flag)
	{
		if (flag && this.onChange != null)
		{
			this.onChange.Invoke(false);
		}
	}

	// Token: 0x060017DF RID: 6111 RVA: 0x0009CE1C File Offset: 0x0009B01C
	public EventTrigger GetEventTrigger()
	{
		EventTrigger component = base.GetComponent<EventTrigger>();
		if (component)
		{
			return component;
		}
		return base.gameObject.AddComponent<EventTrigger>();
	}

	// Token: 0x04001B4D RID: 6989
	[SerializeField]
	private Text title;

	// Token: 0x04001B4E RID: 6990
	[SerializeField]
	private Toggle on;

	// Token: 0x04001B4F RID: 6991
	[SerializeField]
	private Toggle off;

	// Token: 0x04001B50 RID: 6992
	[SerializeField]
	private bool value;

	// Token: 0x04001B51 RID: 6993
	[SerializeField]
	private Image noIntaractImage;

	// Token: 0x04001B52 RID: 6994
	[SerializeField]
	private SwitchUI.SwitchEvent onChange;

	// Token: 0x04001B53 RID: 6995
	private bool invoke = true;

	// Token: 0x04001B54 RID: 6996
	private bool intaractable = true;

	// Token: 0x020003BE RID: 958
	[Serializable]
	private class SwitchEvent : UnityEvent<bool>
	{
	}
}
